package com.free.plan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.free.common.core.web.domain.R;
import com.free.plan.service.DevPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.free.common.log.annotation.Log;
import com.free.common.log.enums.BusinessType;
import com.free.common.security.annotation.RequiresPermissions;
import com.free.plan.domain.DevPlan;
import com.free.common.core.web.controller.BaseController;
import com.free.common.core.web.domain.AjaxResult;
import com.free.common.core.utils.poi.ExcelUtil;
import com.free.common.core.web.page.TableDataInfo;

/**
 * 开发计划Controller
 *
 * @author free
 * @date 2024-02-08
 */
@RestController
@RequestMapping("/plan" )
public class DevPlanController extends BaseController {
    @Autowired
    private DevPlanService devPlanService;

    /**
     * 查询开发计划列表
     */
    @GetMapping("/list" )
    public TableDataInfo list(DevPlan devPlan) {
        startPage();
        List<DevPlan> list = devPlanService.selectDevPlanList(devPlan);
        return getDataTable(list);
    }

    /**
     * 导出开发计划列表
     */
    @Log(title = "开发计划" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, DevPlan devPlan) {
        List<DevPlan> list = devPlanService.selectDevPlanList(devPlan);
        ExcelUtil<DevPlan> util = new ExcelUtil<DevPlan>(DevPlan.class);
        util.exportExcel(response, list, "开发计划数据" );
    }

    /**
     * 获取开发计划详细信息
     */
    @GetMapping(value = "/{id}" )
    public R getInfo(@PathVariable("id" ) Long id) {
        return R.ok(devPlanService.selectDevPlanById(id));
    }

    /**
     * 新增开发计划
     */
    @Log(title = "开发计划" , businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody DevPlan devPlan) {
        return R.ok(devPlanService.insertDevPlan(devPlan));
    }

    /**
     * 修改开发计划
     */
    @Log(title = "开发计划" , businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody DevPlan devPlan) {
        return R.ok(devPlanService.updateDevPlan(devPlan));
    }

    /**
     * 删除开发计划
     */
    @Log(title = "开发计划" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public R remove(@PathVariable List<Long> ids) {
        return R.ok(devPlanService.deleteDevPlanByIds(ids));
    }
}
